<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        input {
            display: inline-block;
            padding-left: 10px;
            width: 300px;
            height: 50px;
            margin-left: 300px;
            box-sizing: border-box;
            border: 1px solid black;
        }

        button {
            outline: none;
            padding: 0;
            margin: 0;
            width: 100px;
            height: 30px;
            border: 1px solid black;
            margin-left: 100px;
        }
    </style>
</head>

<body>
    <input type="text" placeholder="请输入11位的手机号">
    <button>发送</button>
    <script>
        var input_1 = document.querySelector("input");
        var button = document.querySelector("button");
        button.onclick = function () {
            var str = input_1.value;
            var regE01 = /^1/;
            var regE03 = /\D/;
            if(regE03.test(str)) {
                alert("出现了字母，请重新输入");
                return ;
            }
            if(regE01.test(str)) {
            }else {
                console.log("请以1开头输入手机号");
                alert("请以1开头输入手机号");
                return ;
            }
            var regE02 = /[3-9]/;
            if(regE02.test(str[1])) {
            }else {
                alert("第二个数字必须大于等于三小于等于9");
                return ;
            }
            var regExp = /\d/g;
            var res = str.match(regExp).join("");
            if (res.length == 11) {
                alert("这是正确的手机号码");
                console.log("这是正确的手机号码");
                // console.log(str[1]);
            } else {
                alert("数字长度不正确");
                return ;
            }
        }

    </script>
</body>

</html>